{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "132e731a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d18c0c23-b442-438d-aa7d-5480c7d20d82",
   "metadata": {},
   "source": [
    "### 面向对象 类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "08d7eee1-03b7-458c-ac90-3ad0e81438f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<__main__.Person object at 0x000001F6F4580E30>\n",
      "3 2\n",
      "我是人类, 我有私有属性年龄0, 我在思考\n"
     ]
    }
   ],
   "source": [
    "# class Person(object):  object是python基类，可以省略\n",
    "class Person:\n",
    "    eyes = 2   # 类的属类或变量\n",
    "    leg = 2\n",
    "    norse = 1  # 公有属性\n",
    "    __age = 0  # 私属性\n",
    "\n",
    "    def talk(self):  # 公有方法，外部可调用\n",
    "        print(f'我是人类, 我有私有属性年龄{self.__age}, {self.__thinking()}') # 私有属生调用时要加self, 只能在类的内部调用\n",
    "\n",
    "    def __thinking(self): # 私有方法，只能在内部调用\n",
    "        return '我在思考'\n",
    "\n",
    "p1 = Person()   # 实例化类，生一个对象（实体）\n",
    "print(p1)\n",
    "p1.eyes = 3\n",
    "print(p1.eyes, p1.leg)\n",
    "# print(p1.__age) # 私有属性外部是不可见的\n",
    "\n",
    "p1.talk()\n",
    "# Person.talk()\n",
    "# p1.__thinking()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e85df28",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Cat:\n",
    "    leg = 4  # 类的公有属性\n",
    "    ears = 2\n",
    "    _lifes = 9 # 类的私有属性\n",
    "\n",
    "    def_init_(self, name, colour): \n",
    "       self. name = name  \n",
    "       self. colour = black\n",
    "    \n",
    "    def meow(self):\n",
    "        print(p1.eyes,pl.leg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a82022c-82f5-4cf5-8e3d-9993793ec532",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000\n",
      "1000\n",
      "1000\n"
     ]
    }
   ],
   "source": [
    "# 类方法 @classmethod\n",
    "class Cat:\n",
    "    __attr = 1000\n",
    "\n",
    "    @classmethod\n",
    "    def print_attr(cls):\n",
    "        print(cls.__attr)\n",
    "\n",
    "Cat.print_attr()\n",
    "cat = Cat()\n",
    "cat.print_attr()\n",
    "\n",
    "# 类的静态方法 @staticmethod\n",
    "class Cat: \n",
    "    \n",
    "    # 静态方法\n",
    "    @staticmethod\n",
    "    def print_attr2():\n",
    "        print('static1000')\n",
    "Cat.print_attr2()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27c68855",
   "metadata": {},
   "outputs": [],
   "source": [
    " class Dog:\n",
    "     def __init__(self):\n",
    "        self.name = NameError\n",
    "        self.age = age\n",
    "\n",
    "        class\n",
    "        def from (cls,name,birth_year):\n",
    "            current_year = 2024\n",
    "        age= current_year - birth_year\n",
    "        return cls(name,age)\n",
    "         "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
